package com.song.JavaThread_day04.ch4_12;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class TaskMain {
	
	public static void main(String[] args) {
		
		RejectedTaskController controller = new RejectedTaskController();
		
		ThreadPoolExecutor executor  =(ThreadPoolExecutor)Executors.newCachedThreadPool();
		
		executor.setRejectedExecutionHandler(controller);
		
		System.out.println("Main : Starting    ");
		
		for(int i=0; i<3;i++)
		{
			 Task task = new Task("task-" +i);
			 executor.submit(task);
		}
		
		System.out.printf(" Main : Shutting down the Executor \n");
		executor.shutdown();
		
		System.out.printf("main :sending another Task \n");
		Task task = new Task(" RejectedTask ");
		executor.submit(task);
		
		System.out.println(" Main : End");
		System.out.printf(" Main : End \n");
		
	}
	
}
